<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-steps :active="step" align-center class="steps" finish-status="success">
          <el-step title="创建样本"></el-step>
          <el-step title="虚拟入库"></el-step>
          <el-step title="提交申请"></el-step>
          <el-step title="完成"></el-step>
        </el-steps>
      </el-col>
      <el-col v-show="step==0" :span="24">
        <el-card class="box-card">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['biobank:sample:add']"
                icon="el-icon-plus"
                plain
                size="mini"
                type="primary"
                @click="handleAdd"
              >创建新样本
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['biobank:sample:print']"
                :disabled="multiple"
                icon="el-icon-printer"
                plain
                size="mini"
                type="success"
                @click="handlePrint"
              >打印条码
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['biobank:sample:import']"
                icon="el-icon-upload2"
                plain
                size="mini"
                type="info"
                @click="handleSampleImport"
              >导入
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['biobank:sample:remove']"
                :disabled="multiple"
                icon="el-icon-delete"
                plain
                size="mini"
                type="danger"
                @click="handleDelete"
              >删除
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-select v-model="queryParams.own" placeholder="请选择" size="small" @change="ownChange">
                <el-option
                  v-for="item in ownOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-col>
            <right-toolbar showSearch.sync="false" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table v-loading="loading" :data="sampleList" @selection-change="handleSelectionChange">
            <el-table-column align="center" type="selection" width="55"/>
            <el-table-column align="center" label="样本复份编号" min-width="110" prop="sampBackupCode"/>
            <el-table-column align="center" label="样本类型" prop="sampTypeName" width="180px">
              <template slot-scope="scope">
                <treeselect v-show="scope.row.editShow"
                            v-model="scope.row.sampTypeId"
                            :appendToBody="true"
                            :clearable="false"
                            :normalizer="normalizerSampType"
                            :options="sampleTypeOptions"
                            placeholder="请选择样本类型"
                            @select="sampleTypeSelect"
                />
                <span v-show="!scope.row.editShow">{{ scope.row.sampTypeName }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="样本源编号" prop="sampSourceCode"/>
            <el-table-column align="center" label="样本源名称" prop="sampSourceName"/>
            <el-table-column align="center" label="采样时间" prop="samplingTime" width="180">
              <template slot-scope="scope">
                <el-date-picker v-show="scope.row.editShow"
                                v-model="scope.row.samplingTime"
                                :clearable="false"
                                placeholder="选择采样时间"
                                size="small"
                                style="width: 100%"
                                type="datetime"
                                value-format="yyyy-MM-dd HH:mm:ss"
                />
                <span v-show="!scope.row.editShow">{{ parseTime(scope.row.samplingTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="样本源类型" prop="sampSourceTypeName"/>
            <el-table-column align="center" label="样本组" prop="sampGroupName" width="180px">
              <template slot-scope="scope">
                <treeselect v-show="scope.row.editShow"
                            v-model="scope.row.sampGroupId"
                            :appendToBody="true"
                            :clearable="false"
                            :normalizer="normalizerSampGroup"
                            :options="sampleGroupOptions"
                            placeholder="请选择样本组"
                            size="small"
                />
                <span v-show="!scope.row.editShow">{{ scope.row.sampGroupName }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="样本量" prop="sampQuantity" width="100px">
              <template slot-scope="scope">
                <el-input v-show="scope.row.editShow" v-model="scope.row.sampQuantity" placeholder="样本量" size="small"
                ></el-input>
                <span v-show="!scope.row.editShow">{{ scope.row.sampQuantity }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="样本单位" prop="sampUnit" width="120px">
              <template slot-scope="scope">
                <el-input v-show="scope.row.editShow" v-model="scope.row.sampUnit" placeholder="样本单位" size="small"
                ></el-input>
                <span v-show="!scope.row.editShow">{{ scope.row.sampUnit }}</span>
              </template>
            </el-table-column>
            <el-table-column :formatter="sampStateFormat" align="center" label="样本状态" prop="sampState"/>
            <el-table-column align="center" label="条码/二维码" prop="qrCode">
              <template slot-scope="scope">
                <el-input v-show="scope.row.editShow" v-model="scope.row.qrCode" placeholder="条码/二维码" size="small"
                ></el-input>
                <span v-show="!scope.row.editShow">{{ scope.row.qrCode }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="操作" width="180">
              <template slot-scope="scope">
                <div v-show="!scope.row.editShow">
                  <el-button icon="el-icon-edit" size="mini" type="text" @click="handleEdit(scope.$index, scope.row)">
                    编辑
                  </el-button>
                  <el-button icon="el-icon-printer" size="mini" type="text" @click="handlePrint(scope.row)">打印
                  </el-button>
                  <el-button icon="el-icon-delete" size="mini" type="text" @click="handleDelete(scope.row)">删除
                  </el-button>
                </div>
                <div v-show="scope.row.editShow">
                  <el-button icon="el-icon-close" size="mini" type="text"
                             @click="handleCancel(scope.$index, scope.row)"
                  >取消
                  </el-button>
                  <el-button icon="el-icon-check" size="mini" type="text" @click="handleSave(scope.$index, scope.row)">
                    保存
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total>0"
            :limit.sync="queryParams.pageSize"
            :page.sync="queryParams.pageNum"
            :total="total"
            @pagination="getList"
          />
        </el-card>
        <el-button v-hasPermi="['biobank:stockIn:edit']" class="bottom-btn" type="success" @click="virtualInStock">
          下一步：虚拟入库
        </el-button>
      </el-col>
      <el-col v-show="step==1" :span="24">
        <el-card class="box-card">
          <!-- 虚拟入库 -->
          <el-row>
            <el-col :span="13">
              <el-table ref="virtualTable" :data="selectSamples" max-height="690"
                        @selection-change="virtualSelectionChange"
              >
                <el-table-column align="center" type="selection" width="55"/>
                <el-table-column align="center" label="样本复份编号" prop="sampBackupCode"/>
                <el-table-column align="center" label="样本源名称" prop="sampSourceName"/>
                <el-table-column align="center" label="样本源类型" prop="sampSourceTypeName"/>
                <el-table-column align="center" label="样本组" prop="sampGroupName"/>
                <el-table-column align="center" label="样本位置" prop="sampLocation" width="240"/>
                <el-table-column align="center" label="条码/二维码" prop="qrCode"/>
              </el-table>
            </el-col>

            <el-col :span="11">
              <el-row :gutter="10" class="mb8" style="margin-left: 16px">
                <el-col :span="1.3">
                  <el-button icon="el-icon-aim" plain size="mini" type="primary" @click="virtualSelectBox">选择冻存盒
                  </el-button>
                </el-col>
                <el-col :span="1.3">
                  <el-button icon="el-icon-check" plain size="mini" type="success" @click="virtualConfirmLoc">确认样本位置
                  </el-button>
                </el-col>
                <el-col :span="1.3">
                  <el-button plain size="mini" type="info" @click="scanAllBox">
                    <svg-icon icon-class="scan"></svg-icon>
                    整盒扫描
                  </el-button>
                </el-col>
                <el-col :span="1.3">
                  <el-button icon="el-icon-upload2" plain size="mini" type="warning" @click="uploadByExcel">Excel导入
                  </el-button>
                </el-col>
                <el-col :span="1.3">
                  <el-button icon="el-icon-refresh" plain size="mini" type="danger" @click="virtualClearLoc">清空样本位置
                  </el-button>
                </el-col>
              </el-row>

              <div v-if="selectContainer && Object.keys(selectContainer).length != 0">
                <span style="margin-left: 21px; font-size: 14px">{{ selectContainer.containerLocation }}</span>
                <el-button icon="el-icon-close" size="mini" style="padding-left: 16px" type="text"
                           @click="virtualDelBox"
                >删除冻存盒
                </el-button>
              </div>
              <el-table v-if="selectTubes && selectTubes.length > 0" :key="tubeTableKey" :data="selectTubes"
                        :row-style="{'height': 540/selectContainer.boxRow + 'px'}" border class="customer-table"
                        height="590px" style="margin-left: 21px; margin-top: 10px; width: 583px"
                        @cell-click="tableCellClick"
              >
                <el-table-column align="center" type="index" width="42">
                  <template slot-scope="scope">
                    <span>{{ tubeRow[scope.$index] }}</span>
                  </template>
                </el-table-column>
                <el-table-column v-for="(item, index) in selectTubes" :key="index" :label="index + 1 + ''"
                                 :width="540/selectContainer.boxColumn" align="center"
                >
                  <template slot-scope="scope">
                    <el-popover
                      placement="right"
                      trigger="hover"
                      width="230"
                    >
                      <div v-if="scope.row[index].sample">
                        <div>样本状态：{{ sampStateFormat(scope.row[index].sample) }}</div>
                        <div><span>复份编号：{{ scope.row[index].sample.sampBackupCode }}</span></div>
                        <div><span>样本源名称：{{ scope.row[index].sample.sampSourceName }}</span></div>
                        <div><span>样本类型名称：{{ scope.row[index].sample.sampTypeName }}</span></div>
                        <div><span>样本组：{{ scope.row[index].sample.sampGroupName }}</span></div>
                        <div><span>条码/二维码：{{ scope.row[index].sample.qrCode }}</span></div>
                      </div>
                      <svg-icon v-if="scope.row[index].sample"
                                slot="reference"
                                :class="scope.row[index].sample.sampState === '1' ? 'table-icon' : 'table-icon-blur'"
                                :icon-class="scope.row[index].sample.sampTypeIcon"
                      />
                    </el-popover>
                    <svg-icon v-if="scope.row[index].tubeState === '2'" class="table-icon" icon-class="disable"/>
                    <svg-icon v-if="scope.row[index].tubeState === '1'" class="table-icon" icon-class="broken"/>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
        </el-card>
        <div class="bottom-btn">
          <el-button type="primary" @click="step = 0">上一步</el-button>
          <el-button type="success" @click="step = 2">下一步：提交申请</el-button>
        </div>
      </el-col>
      <el-col v-show="step==2" :span="24">
        <el-card class="box-card">
          <el-input v-model="approveForm.stockTitle" clearable placeholder="请输入单据标题">
            <template slot="prepend">单据标题</template>
          </el-input>
          <editor v-model="approveForm.stockDesc" :min-height="480"/>
          <file-upload :value="approveForm.attaches" style="margin-top: 16px" @fileEvent="fileUploadEvent"
          ></file-upload>


          <el-form :inline="true" style="margin-top: 16px">
            <el-form-item label="课题名称" prop="sampState">
              <el-select
                v-model="selectTopicId"
                clearable
                placeholder="课题名称"
                size="small"
                style="width: 240px"
                @change="topicChangeEvent"
              >
                <el-option
                  v-for="dict in topicList"
                  :key="dict.topicId"
                  :label="dict.topicName"
                  :value="dict.topicId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="课题任务">
              <el-select
                v-model="selectTaskId"
                clearable
                placeholder="课题任务"
                size="small"
                style="width: 240px"
              >
                <el-option
                  v-for="dict in taskList"
                  :key="dict.taskId"
                  :label="dict.taskName"
                  :value="dict.taskId"
                />
              </el-select>
            </el-form-item>
          </el-form>
        </el-card>
        <div class="bottom-btn">
          <el-button type="primary" @click="step = 1">上一步</el-button>
          <el-button :loading="applying" type="success" @click="confirmApprove">下一步：完成</el-button>
        </div>
      </el-col>
      <el-col v-show="step==3" :span="24">
        <el-card align="center" class="box-card">
          <h1 style="margin-top: 160px">入库申请成功</h1>
          <el-button type="primary" @click="keepAdd">继续申请</el-button>
        </el-card>
      </el-col>
    </el-row>

    <!-- 创建样本 对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="60%">
      <el-form ref="form" :model="form" :rules="rules" label-width="96px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="样本源编号" prop="sourceCode">
              <el-input v-model="form.sourceCode" placeholder="请输入样本源编号" @change="getSourceDetail"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="样本源名称" prop="sourceName">
              <el-input v-model="form.sourceName" placeholder="请输入样本源名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="随访状态" prop="followState">
              <el-select
                v-model="form.followState"
                clearable
                placeholder="随访状态"
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in followStateOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="样本源类型" prop="sourceTypeId">
              <treeselect v-model="form.sourceTypeId" :normalizer="normalizerSourceType" :options="sourceTypeOptions"
                          placeholder="请选择样本源类型"
                          @select="sourceTypeSelect"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="样本源描述" prop="sourceDesc">
              <el-input v-model="form.sourceDesc" :rows="2" placeholder="请输入样本源描述" type="textarea"></el-input>
            </el-form-item>
            <el-input v-if="false" v-model="form.formKey" placeholder="请输入自定义表单key"/>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div
              v-for="(domain, index) in form.formJson"
              :key="index"
              :label="domain.controlLable"
            >
              <parser ref="formCustom" :form-conf="domain.json"/>
            </div>
          </el-col>
        </el-row>
        <file-upload :value="form.attaches" style="margin-top: 16px" @fileEvent="sourceFileEvent"></file-upload>
        <el-divider><i class="el-icon-s-promotion"></i></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="样本编号" prop="sampBackupCode">
              <el-input v-model="form.sampCode" placeholder="样本编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="样本类型" prop="sampTypeId">
              <treeselect v-model="form.sampTypeId" :normalizer="normalizerSampType" :options="sampleTypeOptions"
                          placeholder="请选择样本类型"
                          @select="sampleTypeSelect"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="样本组" prop="sampGroupId">
              <treeselect v-model="form.sampGroupId" :normalizer="normalizerSampGroup" :options="sampleGroupOptions"
                          placeholder="请选择样本组"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="样本复份数" prop="sampBackupCount">
              <el-input-number v-model="form.sampBackupCount" :min="1" controls-position="right" placeholder="请输入样本复份数"
                               style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <!--          <el-col :span="12">-->
          <!--            <el-form-item label="冻存管类型" prop="tubeType">-->
          <!--              <el-select-->
          <!--                v-model="form.tubeType"-->
          <!--                placeholder="冻存管类型"-->
          <!--                clearable-->
          <!--                size="small"-->
          <!--                style="width: 100%"-->
          <!--              >-->
          <!--                <el-option-->
          <!--                  v-for="dict in tubeTypeOptions"-->
          <!--                  :key="dict.dictValue"-->
          <!--                  :label="dict.dictLabel"-->
          <!--                  :value="dict.dictValue"-->
          <!--                />-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="样本量" prop="sampQuantity">
              <el-input v-model="form.sampQuantity" placeholder="请输入样本量"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="样本单位" prop="sampUnit">
              <el-input v-model="form.sampUnit" placeholder="请输入样本单位"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="采样时间" prop="samplingTime">
              <el-date-picker v-model="form.samplingTime" clearable
                              placeholder="选择采样时间"
                              size="small"
                              style="width: 100%"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 容器树 对话框 -->
    <el-dialog :visible.sync="treeVisible" append-to-body title="选择冻存盒" width="40%">
      <el-tree
        ref="containerTree"
        :data="containerList"
        :expand-on-click-node="true"
        :highlight-current="highlightCurrent"
        :load="loadLazyTree"
        :props="containerTreeProps"
        lazy
        node-key="containerId"
        style="height: 480px; overflow: auto; min-width: 100%; display: inline-block"
        @node-click="treeNodeClick"
      >
          <span slot-scope="{ node, data }">
            <svg-icon :icon-class="data.containerIcon" style="margin-right: 3px"/>
            <span>{{ node.label }}</span>
            <span :style="judgeColor(data.storageRate)">{{ data.storageRate }}%</span>
          </span>
      </el-tree>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmBoxSelect">确 定</el-button>
        <el-button @click="cancelBoxSelect">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 样本导入 对话框 -->
    <el-dialog :title="sampleUpload.title" :visible.sync="sampleUpload.open" append-to-body width="400px">
      <el-upload
        ref="sampleUpload"
        :action="sampleUpload.url + '?updateSupport=' + sampleUpload.updateSupport"
        :auto-upload="false"
        :disabled="sampleUpload.isUploading"
        :headers="sampleUpload.headers"
        :limit="1"
        :on-progress="handleSampleUploadProgress"
        :on-success="handleSampleUploadSuccess"
        accept=".xlsx, .xls"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div slot="tip" class="el-upload__tip">
          <el-checkbox v-model="sampleUpload.updateSupport"/>
          是否更新已经存在的样本源
          <el-link style="font-size:12px" type="info" @click="sampleImportTemplate">下载模板</el-link>
        </div>
        <div slot="tip" class="el-upload__tip" style="color:red">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitSampleUploadForm">确 定</el-button>
        <el-button @click="sampleUpload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- excel导入二维码 对话框 -->
    <el-dialog :visible.sync="upload.open" append-to-body title="Excel导入" width="400px">
      <el-upload
        ref="upload"
        :auto-upload="false"
        :file-list="upload.updateFile"
        :limit="1"
        :on-change="handleUploadChange"
        :on-remove="handleUploadRemove"
        accept=".xlsx, .xls"
        action=""
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div slot="tip" class="el-upload__tip">
          <el-checkbox v-model="upload.updateSupport"/>
          是否更新已经存在的二维码
          <el-link style="font-size:12px" type="info" @click="downloadTemplate">下载模板</el-link>
        </div>
        <div slot="tip" class="el-upload__tip" style="color:red">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitExcel">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {
  createSample,
  delSample,
  getImportTemplate,
  getQrCodeTemplate,
  listSample,
  updateSample,
  updateSamples
} from '@/api/biobank/sample'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Parser from 'form-gen-parser'
import Editor from '@/components/Editor'
import FileUpload from '@/components/FileUpload'
import { listSourceType } from '@/api/biobank/sourceType'
import { getSourceByCode } from '@/api/biobank/source'
import { formJsonShow } from '@/api/tool/form'
import { getSampleType, listSampleType } from '@/api/biobank/sampleType'
import { listSampleGroup } from '@/api/biobank/sampleGroup'
import { lazyTree } from '@/api/biobank/container'
import { clearLocation, confirmLocation, listTube } from '@/api/biobank/tube'
import { addStock } from '@/api/activiti/stock'
// import axios from 'axios'
import { getActiveTemp } from '@/api/tool/labelTemp'
import XLSX from 'xlsx'
import { getToken } from '@/utils/auth'
import { listAllTopic } from '@/api/research/topic'
import { addRelate, listAllTask } from '@/api/research/task'

export default {
  name: 'StockIn',
  components: {
    Treeselect,
    Parser,
    Editor,
    FileUpload
  },
  data() {
    return {
      step: 0,
      // 遮罩层
      loading: true,
      // 非多个禁用
      multiple: true,
      // 选中数组
      ids: [],
      // 选中的样本复份
      selectSamples: [],
      // 虚拟入库 选中的容器盒
      selectContainer: {},
      // 虚拟入库 选中盒的冻存管
      selectTubes: [],
      // 虚拟入库 选中的样本复份
      virtualSelectSamples: [],
      // 虚拟入库 选中单元格的试管
      virtualSelectTube: {},
      // 虚拟入库 容器树 数据
      containerList: [],
      // 虚拟入库 前一次选中的cell
      oldSelectTableCell: undefined,
      // 申请单关联的所有样本
      approveSamples: [],
      // 容器树
      containerTreeProps: {
        children: 'children',
        label: 'title',
        isLeaf: 'leaf'
      },
      // 容器树对话框
      treeVisible: false,
      // 容器树是否高亮选中
      highlightCurrent: false,
      // 总条数
      total: 0,
      ownOptions: [
        {
          value: '0',
          label: '我的'
        },
        {
          value: '1',
          label: '所有'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'createTime',
        isAsc: 'DESC',
        sampState: '0,3',// 虚拟,待入库
        stockState: '0',
        own: '0' // 0-我的 1-所有
      },
      // 二维码excel导入
      upload: {
        // 是否显示弹出层
        open: false,
        // 是否更新已经存在的二维码
        updateSupport: false,
        // 上传的文件
        updateFile: []
      },
      // 样本excel导入
      sampleUpload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的样本源
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/biobank/sample/importData'
      },
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 弹出层是否显示样本源数据
      sampTypeShow: true,
      // 样本复份 表格数据
      sampleList: [],
      // 提交申请 附件列表
      uploadFileList: [],
      // 审批表单
      approveForm: {},
      // 样本状态
      sampStateOptions: [],
      // 冻存管类型
      tubeTypeOptions: [],
      // 随访状态
      followStateOptions: [],
      // 样本源类型 树选项
      sourceTypeOptions: [],
      // 样本类型 树选项
      sampleTypeOptions: [],
      // 样本组 树选项
      sampleGroupOptions: [],
      // 表格行值
      tubeRow: this.GLOBAL.TUBE_ROW,
      // 试管table的key 为了data更改后视图更新
      tubeTableKey: 0,
      // 启用的打印标签模板
      activeLabelTemp: {},
      // 申请中
      applying: false,
      // 表单参数
      form: {},
      // 课题名称列表
      topicList: [],
      // 选中的课题
      selectTopicId: undefined,
      // 课题任务列表
      taskList: [],
      // 选中的课题任务
      selectTaskId: undefined,
      // 表单校验
      rules: {
        sourceCode: { required: true, trigger: 'blur', message: '请输入样本源编号' },
        sourceName: { required: true, trigger: 'blur', message: '请输入样本源名称' },
        sourceTypeId: { required: true, trigger: 'change', message: '请选择样本源类型' },
        sampTypeId: { required: true, trigger: 'change', message: '请选择样本类型' },
        sampGroupId: { required: true, trigger: 'change', message: '请选择样本组' },
        sampBackupCount: { required: true, trigger: 'blur', message: '请输入样本复份数' }
        // tubeType: { required: true, trigger: 'change', message: '请选择冻存管类型' },
      }
    }
  },
  created() {
    this.getList()
    this.getDicts('sample_state').then(response => {
      this.sampStateOptions = response.data
    })
    this.getDicts('follow_state').then(response => {
      this.followStateOptions = response.data
    })
    this.getDicts('tube_type').then(response => {
      this.tubeTypeOptions = response.data
    })
    this.getSourceTypeList()
    this.getSampleGroupList()
    this.getSampleTypeList()
    this.getActiveLabelTemp()
    listAllTopic().then(response => {
      this.topicList = response.data
    })
  },
  methods: {
    // 课题选择事件
    topicChangeEvent() {
      this.taskList = []
      this.selectTaskId = undefined
      if (!this.selectTopicId) {
        return false
      }
      listAllTask(this.selectTopicId).then(response => {
        this.taskList = response.data
      })
    },

    // 获取当前启用的标签模板
    getActiveLabelTemp() {
      getActiveTemp().then(response => {
        this.activeLabelTemp = response.data
      })
    },
    // excel导入二维码
    uploadByExcel() {
      if (!this.selectTubes || this.selectTubes.length === 0) {
        this.$message.warning('请先选择冻存盒')
        return false
      }
      this.upload.open = true
      this.upload.updateSupport = false
      this.upload.updateFile = []
    },
    // 文件上传
    handleUploadChange(file, fileList) {
      this.upload.updateFile = [file]
    },
    // 文件删除
    handleUploadRemove(file, fileList) {
      this.upload.updateFile = []
    },
    // 下载模板
    downloadTemplate() {
      getQrCodeTemplate().then(response => {
        this.download(response.msg)
      })
    },
    // excel导入确定按钮点击事件
    submitExcel() {
      if (!this.upload.updateFile || this.upload.updateFile.length === 0) {
        this.$message.warning('请先上传Excel文件')
      }
      new Promise((resolve, reject) => {
        const reader = new FileReader()
        reader.onload = e => {
          const data = e.target.result
          const workbook = XLSX.read(data, { type: 'array' })
          const firstSheetName = workbook.SheetNames[0]
          const worksheet = workbook.Sheets[firstSheetName]
          const results = XLSX.utils.sheet_to_json(worksheet)

          if (results && results instanceof Array) {
            let samples = []
            let tubesArray = this.selectTubes.reduce((prev, next) => {
              return prev.concat(next)
            })
            tubesArray.forEach(item => {
              results.forEach(qr => {
                if (item.sample && item.tubeSort === qr.order && qr.code !== 'NoData') {
                  if (item.sample.qrCode && item.sample.qrCode !== '') {
                    if (this.upload.updateSupport) { // 已存在的二维码是否更新
                      item.sample.qrCode = qr.code
                    }
                  } else {
                    item.sample.qrCode = qr.code
                  }
                  samples.push(item.sample)
                }
              })
            })
            this.convertArray(tubesArray)
            resolve(samples)
          } else {
            this.$message.warning('未获取到数据，请检查Excel文件')
          }
        }
        reader.readAsArrayBuffer(this.upload.updateFile[0].raw)
      }).then(samples => {
        this.upload.open = false
        this.virtualSelectSamples.forEach(i => {
          samples.forEach(j => {
            if (i.sampBackupId === j.sampBackupId) {
              i.qrCode = j.qrCode
            }
          })
        })
        return updateSamples(samples)
      }).then(res => {
        this.msgSuccess('更新二维码信息成功')
      }).catch(err => {
        this.upload.open = false
        this.$message.error('请导入正确的Excel文件')
      })
    },
    // 整盒扫描
    scanAllBox() {
      if (!this.selectTubes || this.selectTubes.length === 0) {
        this.$message.warning('请先选择冻存盒')
        return false
      }
      // axios.get('/scan-api/readResultData').then(res => {
      this.$jsonp('http://localhost:63668/readResultData', {
        callback: 'jsonp'
      }).then(res => {
        if (res.data && res.data instanceof Array) {
          let samples = []
          let tubesArray = this.selectTubes.reduce((prev, next) => {
            return prev.concat(next)
          })
          tubesArray.forEach(item => {
            res.data.forEach(qr => {
              if (item.sample && item.tubeSort === qr.order && qr.code !== 'NoData') {
                item.sample.qrCode = qr.code
                samples.push(item.sample)
              }
            })
          })
          this.convertArray(tubesArray)
          return samples
        } else {
          this.$message.warning('未获取到扫码结果，请正确放置冻存盒')
        }
      }).then(res => {
        this.virtualSelectSamples.forEach(i => {
          res.forEach(j => {
            if (i.sampBackupId === j.sampBackupId) {
              i.qrCode = j.qrCode
            }
          })
        })
        return updateSamples(res)
      }).then(res => {
        this.msgSuccess('更新二维码信息成功')
      }).catch(err => {
        this.$message.error('请确认批量扫码仪是否连接正确或BarcodeReader是否打开')
      })
    },
    // 导入样本按钮点击事件
    handleSampleImport() {
      this.sampleUpload.title = '样本信息导入'
      this.sampleUpload.open = true
    },
    /** 下载模板操作 */
    sampleImportTemplate() {
      getImportTemplate().then(response => {
        this.download(response.msg)
      })
    },
    // 文件上传中处理
    handleSampleUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleSampleUploadSuccess(response, file, fileList) {
      this.sampleUpload.open = false
      this.sampleUpload.isUploading = false
      this.$refs.sampleUpload.clearFiles()
      this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
      this.getList()
    },
    submitSampleUploadForm() {
      this.$refs.sampleUpload.submit()
    },
    // 提交审批
    confirmApprove() {
      if (!this.approveSamples || this.approveSamples.length === 0) {
        this.$message.warning(`请先确认要入库的样本及位置`)
        return false
      }
      this.approveForm.stockType = this.GLOBAL.STOCK_TYPE.IN//"in"
      this.approveForm.sampleBackups = this.approveSamples
      this.approveForm.attaches = this.uploadFileList

      this.applying = true
      addStock(this.approveForm).then(response => {
        if (this.selectTaskId) {
          let params = []
          this.selectSamples.forEach((item, index) => {
            let param = {}
            param.taskId = this.selectTaskId
            param.sampBackupId = item.sampBackupId
            params.push(param)
          })
          return addRelate(params)
        } else {
          return Promise.resolve()
        }
      }, error => {
        this.applying = false
      }).then(res => {
        this.$message.success(`入库申请提交成功`)
        this.applying = false
        this.step = 3
      })
    },
    // 继续添加 直接刷新页面
    keepAdd() {
      // this.$router.go(0); // 刷新界面
      this.step = 0
      this.$store.dispatch('tagsView/delCachedView', this.$route).then(() => {
        this.$nextTick(() => {
          this.$router.replace({
            path: '/redirect' + this.$route.fullPath
          })
        })
      })
    },
    // 下一步 虚拟入库
    virtualInStock() {
      if (this.selectSamples.length === 0) {
        this.$message.warning(`请先选择要入库的样本`)
      } else {
        this.step = 1
        this.$set(this.approveForm, 'stockTitle', this.$store.getters.nickName + '的样本入库申请')
      }
    },
    // 虚拟入库 多选框选中事件
    virtualSelectionChange(selection) {
      this.virtualSelectSamples = selection
      this.virtualSelectSamples.forEach(item => {
        if (item.sampState === this.GLOBAL.SAMPLE.TO_IN && this.approveSamples.indexOf(item) === -1) { // sampState === '3'
          this.approveSamples.push(item)
        }
      })
    },
    // 选择冻存盒 按钮点击事件 -> 弹出树
    virtualSelectBox() {
      this.treeVisible = true
    },
    // 附件上传子组件回调
    fileUploadEvent(fileList) {
      this.uploadFileList = fileList
    },
    // 创建样本源附件上传子组件回调
    sourceFileEvent(fileList) {
      this.form.attaches = fileList
    },
    // 确认样本位置 按钮点击事件
    virtualConfirmLoc() {
      if (!this.virtualSelectSamples || this.virtualSelectSamples.length === 0) {
        this.$message('请先选择要确认位置的样本')
        return false
      }
      let hasConfirmLocSamp = false
      this.virtualSelectSamples.forEach(item => {
        if (item.sampLocation && item.sampLocation !== '') {
          hasConfirmLocSamp = true
        }
      })
      if (hasConfirmLocSamp) {
        this.$message.warning('当前选中的样本中存在已确认位置的样本，若要重新确认位置请先清空该样本的位置')
        return false
      }
      if (!this.virtualSelectTube || Object.keys(this.virtualSelectTube).length === 0) {
        this.$message('请先选择冻存管位置')
        return false
      }
      // 二维数组转一维数组
      let tubesArray = this.selectTubes.reduce((prev, next) => {
        return prev.concat(next)
      })
      let offset = 0
      tubesArray.forEach((item, index) => {
        let odds = item.tubeSort >= this.virtualSelectTube.tubeSort &&
          (item.sample === undefined || Object.keys(item.sample).length === 0) && offset < this.virtualSelectSamples.length
        if (odds) {
          item.sample = this.virtualSelectSamples[offset]
          this.selectSamples.forEach((sample, i) => {
            if (sample.sampBackupId === this.virtualSelectSamples[offset].sampBackupId) {
              this.virtualSelectSamples[offset].sampLocation = this.selectContainer.containerLocation + '/' + item.tubeLocation
              this.virtualSelectSamples[offset].sampState = this.GLOBAL.SAMPLE.TO_IN
              // 添加进单据关联样本数组
              this.approveSamples.push(this.virtualSelectSamples[offset])
              this.selectSamples.slice(i, 1, this.virtualSelectSamples[offset])
            }
          })
          offset++
          item.sampBackupId = item.sample.sampBackupId
          tubesArray.splice(index, 1, item)
        }
      })
      // 一维数组转二维数组
      this.convertArray(tubesArray)

      // 确认样本位置 成功后清空virtualSelectSamples
      let confirmForm = {}
      confirmForm.sampleBackups = this.virtualSelectSamples
      confirmForm.tubes = tubesArray
      confirmLocation(confirmForm).then(response => {
        this.virtualSelectSamples = []
        this.$refs.virtualTable.clearSelection()
      })
    },
    // 清空样本位置 按钮点击事件
    virtualClearLoc() {
      if (this.oldSelectTableCell && Object.keys(this.oldSelectTableCell).length > 0) {
        this.oldSelectTableCell.removeAttribute('style')
      }
      if (!this.virtualSelectSamples || this.virtualSelectSamples.length === 0) {
        this.$message('请选择要清空位置的样本')
        return false
      }
      this.virtualSelectTube = {}
      this.selectSamples.forEach((sample, index) => {
        this.virtualSelectSamples.forEach(item => {
          if (sample.sampBackupId === item.sampBackupId) {
            // 移出单据关联样本数组
            this.approveSamples.splice(this.approveSamples.indexOf(item), 1)
            item.sampLocation = ''
            item.sampState = this.GLOBAL.SAMPLE.VIRTUAL
            this.selectSamples.splice(index, 1, item)
          }
        })
      })

      if (this.selectTubes && this.selectTubes.length > 0) {
        let tubesArray = this.selectTubes.reduce((prev, next) => {
          return prev.concat(next)
        })
        tubesArray.forEach((item, index) => {
          this.virtualSelectSamples.forEach(sample => {
            if (item.sample && item.sample.sampBackupId === sample.sampBackupId) {
              item.sample = undefined
              item.sampBackupId = undefined
              tubesArray.splice(index, 1, item)
            }
          })
        })
        this.convertArray(tubesArray)
      }

      let clearForm = {}
      clearForm.sampleBackups = this.virtualSelectSamples
      // 清空样本位置
      clearLocation(clearForm).then(response => {
        this.virtualSelectSamples = []
        this.$refs.virtualTable.clearSelection()
      })
    },
    // 删除冻存盒 按钮点击事件
    virtualDelBox() {
      this.selectTubes = []
      this.selectContainer = {}
      this.oldSelectTableCell = undefined
    },
    // 虚拟入库 单元格点击事件
    tableCellClick(row, column, cell, event) {
      let tableCell = row[parseInt(column.label) - 1]
      if (tableCell.tubeState === this.GLOBAL.TUBE.FORBIDDEN || tableCell.tubeState === this.GLOBAL.TUBE.DISABLE) { // tubeState === '2'  tubeState === '1'
        return false
      }
      if (tableCell.sample && Object.keys(tableCell).length !== 0) {
        return false
      }
      if (this.oldSelectTableCell) {
        this.oldSelectTableCell.removeAttribute('style')
      }
      this.virtualSelectTube = tableCell
      cell.setAttribute('style', 'background:#409EFF')
      this.oldSelectTableCell = cell
    },
    // 容器树对话框确定
    confirmBoxSelect() {
      this.treeVisible = false
      if (this.selectContainer && this.selectContainer.containerId) {
        listTube(this.selectContainer.containerId).then(response => {
          const tubes = response.data
          this.convertArray(tubes)
        })
      } else {
        this.$message('请选择一个容器盒')
      }
    },
    // 一维数组转二维数组
    convertArray(tubes) {
      const row = this.selectContainer.boxRow
      const column = this.selectContainer.boxColumn
      this.selectTubes = []

      let itemArr = []
      tubes.forEach(tube => {
        // 如果小数组满了，创建一个新的小数组
        if (itemArr.length === column) {
          itemArr = []
        }
        // 如果小数组是空的，将小数组保存到大数组中
        if (itemArr.length === 0) {
          this.selectTubes.push(itemArr)
        }
        // 保存数据到小数组
        itemArr.push(tube)
      })
      this.tubeTableKey++
    },
    // 容器树对话框 取消按钮点击事件
    cancelBoxSelect() {
      this.treeVisible = false
    },
    // 容器树点击事件
    treeNodeClick(object, Node, element) {
      if (object.containerTypeCode === 'box') {
        this.highlightCurrent = true
        this.selectContainer = object
      } else {
        this.highlightCurrent = false
      }
    },
    // 容器树存储率颜色
    judgeColor(rate) {
      if (rate === 0) {
        return 'color: #909399'
      } else if (rate >= 0 && rate < 40) {
        return 'color: #409EFF'
      } else if (rate >= 40 && rate < 60) {
        return 'color: #67C23A'
      } else if (rate >= 60 && rate < 80) {
        return 'color: #E6A23C'
      } else if (rate >= 80 && rate <= 100) {
        return 'color: #F56C6C'
      }
    },
    /** 懒加载容器 列表 */
    loadLazyTree(node, resolve) {
      if (node.level === 0) {
        lazyTree(0).then(response => {
          resolve(response.data)
        })
      } else {
        lazyTree(node.data.containerId).then(response => {
          if (response.data && response.data.length > 0) {
            response.data.forEach(item => {
              if (item.containerTypeCode === 'box') {
                item.leaf = true
              }
            })
          }
          resolve(response.data)
        })
      }
    },
    // 创建样本 多选框选中事件
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sampBackupId)
      this.selectSamples = selection
      this.multiple = !selection.length
    },
    // 创建新样本对话框
    handleAdd() {
      this.open = true
      this.title = '创建新样本'
    },
    // 打印
    handlePrint(row) {
      const printSamples = row.sampBackupId ? [row] : this.selectSamples
      if (!printSamples || printSamples.length === 0) {
        this.$message.warning('请先选择需打印项')
        return false
      }
      if (!this.activeLabelTemp || !this.activeLabelTemp.labelTempContent) {
        this.$message.warning('当前不存在启用的打印模板')
        return false
      }

      let value = {}
      value.title = this.activeLabelTemp.labelTempName
      value.width = this.activeLabelTemp.labelWidth
      value.height = this.activeLabelTemp.labelHeight
      value.pageWidth = this.activeLabelTemp.labelPageWidth
      value.pageHeight = this.activeLabelTemp.labelPageHeight
      value.tempItems = JSON.parse(this.activeLabelTemp.labelTempContent).tempItems
      // this.$lodop.print(value, printSamples);
      this.$lodop.preview(value, printSamples)
    },
    // 编辑按钮点击事件
    handleEdit(index, row) {
      row.editShow = true
      this.$set(this.sampleList, index, row)
    },
    // 取消按钮点击事件
    handleCancel(index, row) {
      row.editShow = false
      this.$set(this.sampleList, index, row)
    },
    // 保存按钮点击事件
    handleSave(index, row) {
      updateSample(row).then(res => {
        this.$message.success('保存成功')
        row.editShow = false
        this.$set(this.sampleList, index, row)
      })
    },
    // 删除
    handleDelete(row) {
      if (row.sampBackupId) {
        if (row.sampState !== this.GLOBAL.SAMPLE.VIRTUAL) {
          this.$message.warning('不允许删除非虚拟状态的复份样本')
          return false
        }
      } else {
        const exitNotVirtual = this.selectSamples.some(s => {
          return s.sampState !== this.GLOBAL.SAMPLE.VIRTUAL
        })
        if (exitNotVirtual) {
          this.$message.warning('不允许删除非虚拟状态的复份样本')
          return false
        }
      }
      const sampBackupIds = row.sampBackupId || this.ids
      this.$confirm('是否确认删除所选的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delSample(sampBackupIds)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      })
    },
    // 获取待入库样本
    getList() {
      this.loading = true
      listSample(this.queryParams).then(response => {
        this.sampleList = response.rows
        this.sampleList.map(item => {
          item.editShow = false
        })
        this.total = response.total
        this.loading = false
      })
    },
    // 样本所属人切换
    ownChange() {
      this.getList()
    },
    submitForm() {
      if (this.form.formKey) {
        let custFormRef = this.$refs.formCustom[0]
        let custForm = custFormRef.$refs[custFormRef.formConf.formRef]
        let custData = custFormRef[custFormRef.formConf.formModel]
        let custDesc = {}
        for (let onceForm of this.form.formJson) {
          for (let onceField of onceForm.json.fields) {
            if (onceField.__vModel__) {
              custDesc[onceField.__vModel__] = onceField.__config__.label
            } else {
              if (onceField.__config__ && onceField.__config__.children && onceField.__config__.children.length > 0) {
                onceField.__config__.children.forEach(child => {
                  custDesc[child.__vModel__] = child.__config__.label
                })
              }
            }
          }
        }
        let formDataDto = { data: custData, desc: custDesc }
        // 自定义表单的核验
        custForm.validate(e => {
          if (e) {
            this.form.formDataSaveDto = formDataDto
          }
        })
      }

      this.$refs['form'].validate(valid => {
        if (valid) {
          createSample(this.form).then(response => {
            this.msgSuccess('新增成功')
            this.open = false
            this.reset()
            this.getList()
          })
        }
      })
    },
    cancel() {
      this.open = false
      this.reset()
    },
    /** 获取样本源详情 */
    getSourceDetail(content) {
      getSourceByCode(content).then(response => {
        if (response.data && Object.keys(response.data).length > 0) {
          // this.form = response.data;
          this.form.sourceId = response.data.sourceId
          this.form.sourceName = response.data.sourceName
          this.form.sourceDesc = response.data.sourceDesc
          this.form.attaches = response.data.attaches
          this.form.followState = response.data.followState
          this.form.sourceTypeId = response.data.sourceTypeId
          this.form.formKey = response.data.formKey
          this.form.formDesc = response.data.formDesc
          this.form.formData = response.data.formData
          this.showFormJson(this.form.formKey)
        } else {
          this.form = {}
          this.$set(this.form, 'sourceCode', content)
        }
      })
    },
    /** 查询样本类型 列表 */
    getSampleTypeList() {
      listSampleType().then(response => {
        this.sampleTypeOptions = this.handleTree(response.data, 'sampTypeId', 'parentId')
      })
    },
    /** 转换样本类型 数据结构 */
    normalizerSampType(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.sampTypeId,
        label: node.sampTypeName,
        children: node.children
      }
    },
    /** 查询样本组 列表 */
    getSampleGroupList() {
      listSampleGroup().then(response => {
        this.sampleGroupOptions = this.handleTree(response.data, 'sampGroupId', 'parentId')
      })
    },
    /** 转换样本组 数据结构 */
    normalizerSampGroup(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.sampGroupId,
        label: node.sampGroupName,
        children: node.children
      }
    },
    /** 查询样本源类型 列表 */
    getSourceTypeList() {
      listSourceType().then(response => {
        this.sourceTypeOptions = this.handleTree(response.data, 'sourceTypeId', 'parentId')
      })
    },
    /** 转换样本源类型 数据结构 */
    normalizerSourceType(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.sourceTypeId,
        label: node.sourceTypeName,
        children: node.children
      }
    },
    // 样本类型下拉框选择事件
    sampleTypeSelect(node, instanceId) {
      getSampleType(node.sampTypeId).then(response => {
        if (response.data) {
          // this.form = response.data;
          this.$set(this.form, 'sampQuantity', response.data.sampTypeDefaultQuantity)
          this.form.sampUnit = response.data.sampTypeDefaultUnit
          this.form.sampBackupCount = response.data.sampTypeDefaultDuplqty
        }
      })
    },
    // 样本源类型下拉框选择事件
    sourceTypeSelect(node, instanceId) {
      this.form.formKey = node.formKey
      this.showFormJson(node.formKey)
    },
    /** 样本状态状态字典翻译 */
    sampStateFormat(row, column) {
      return this.selectDictLabel(this.sampStateOptions, row.sampState)
    },
    // 渲染动态表单
    showFormJson(formKey) {
      formJsonShow(formKey).then(response => {
        let formJson = []
        for (let oncekey in response.data) {
          let datas = response.data[oncekey]
          if (datas) {
            for (let i = 0; i < datas.length; i++) {
              let once = datas[i]
              if (/^{/.test(once)) {
                formJson.push({
                  json: JSON.parse(once)
                })
              }
            }
          }
        }
        this.$set(this.form, 'formJson', formJson)
        if (this.form.formData != undefined) {
          this.fillFormData(this.form.formJson[0].json, JSON.parse(this.form.formData))
          this.$set(this.form, 'formJson', formJson)
        }
      })
    },
    // 动态表单值回写
    fillFormData(form, data) {
      form.fields.map(item => {
        if (item.__vModel__) {
          const val = data[item.__vModel__]
          if (val) {
            item.__config__.defaultValue = val
          }
          return item
        } else {
          if (item.__config__ && item.__config__.children && item.__config__.children.length > 0) {
            item.__config__.children.forEach(child => {
              const childVal = data[child.__vModel__]
              if (childVal) {
                child.__config__.defaultValue = childVal
              }
            })
            return item
          }
        }
      })
    },
    // 表单重置
    reset() {
      this.form = {
        sourceId: undefined,
        sourceCode: undefined,
        sourceName: undefined,
        sourceDesc: undefined,
        attaches: undefined,
        followState: undefined,
        sourceTypeId: undefined,
        formKey: undefined,
        formJson: undefined,
        formDesc: undefined,
        formData: undefined,
        sampCode: undefined,
        sampTypeId: undefined,
        sampGroupId: undefined,
        sampQuantity: undefined,
        sampUnit: undefined,
        sampBackupCount: undefined,
        tubeType: undefined,
        samplingTime: undefined,
        formDataSaveDto: undefined
      }
      this.resetForm('form')
    }
  }
}
</script>

<style scoped>
.box-card {
  margin-left: 7px;
  margin-right: 7px;
  min-height: 720px;
}

.bottom-btn {
  margin-right: 7px;
  margin-top: 15px;
  float: right
}

.steps {
  width: 80%;
  margin: 10px auto;
}

.table-icon {
  position: absolute;
  top: 5%;
  left: 5%;
  right: 5%;
  bottom: 5%;
  width: 90%;
  height: 90%;
  object-fit: cover;
}

.table-icon-blur {
  position: absolute;
  top: 5%;
  left: 5%;
  right: 5%;
  bottom: 5%;
  width: 90%;
  height: 90%;
  object-fit: cover;
  -webkit-filter: blur(2px);
}

/deep/ .el-input--small .el-input__inner {
  height: 29px;
  line-height: 29px;
}
</style>
